#ifndef SMOPOS_H
#define SMOPOS_H
#include "gd32f30x.h"

typedef struct
{
	int32_t  Valpha;   		// Input: Stationary alfa-axis stator voltage 
	int32_t  Ealpha;   		// Variable: Stationary alfa-axis back EMF 
	int32_t  Zalpha;      	// Output: Stationary alfa-axis sliding control 
	int32_t  Gsmopos;    	// Parameter: Motor dependent control gain 
	int32_t  EstIalpha;  	// Variable: Estimated stationary alfa-axis stator current 
	int32_t  Fsmopos;    	// Parameter: Motor dependent plant matrix 
	int32_t  Vbeta;   		// Input: Stationary beta-axis stator voltage 
	int32_t  Ebeta;  		// Variable: Stationary beta-axis back EMF 
	int32_t  Zbeta;      	// Output: Stationary beta-axis sliding control 
	int32_t  EstIbeta;    	// Variable: Estimated stationary beta-axis stator current 
	int32_t  Ialpha;  		// Input: Stationary alfa-axis stator current 
	int32_t  IalphaError; 	// Variable: Stationary alfa-axis current error                 
	int32_t  Kslide;     	// Parameter: Sliding control gain 
	int32_t  Ibeta;  		// Input: Stationary beta-axis stator current 
	int32_t  IbetaError;  	// Variable: Stationary beta-axis current error                 
	int32_t  Kslf;       	// Parameter: Sliding control filter gain 
	int32_t  Theta;     	// Output: Compensated rotor angle
	int32_t  E0;			// Parameter: 0.5 	
	
	int32_t err;
	int32_t cosine;
	int32_t sine;
	
	int32_t kp;
	int32_t ki;
	int32_t up;
	int32_t ui;
	int32_t omega;
}SMOPOS;

#define SMOPOS_DEFAULTS {  0,0,0,0,0,0,0,0,0,0,0, \
	                       0,0,0,0,0,0,16384   \
              			}

void SMO_Run(SMOPOS *v);

#endif
